/**
 * @Description:
 * @author 若琳
 * @date 2021/8/11
*/


const express = require('express');
const UserOnlineController = express.Router();

const CommonService = require("../../../../../../../../ruoling-system/src/com/ruoling/system/service/v1/common/service.common.js");

const UserOnlineService = require("../../../../../../../../ruoling-system/src/com/ruoling/system/service/v1/monitor/service.useronline.js");
//数据集合
const ResultJson = require("../../../../../../../../ruoling-model/src/com/ruoling/model/SystemModel/ResultJson.js").V("v1.0.0");
const LayuiGrid = require("../../../../../../../../ruoling-model/src/com/ruoling/model/SystemModel/layuiGrid.js");


/**
 * 在线用户视图
 */
UserOnlineController.get("/monitor/useronline/list/view",function (Request,response){

    response.type(".html");
    response.render("admin/monitor/useronline/useronlineview.html");
    return;
});

/**
 * 在线用户列表
 */
UserOnlineController.get("/v1/api/monitor/useronline/list",function (Request,response){

    try{
        let {limit,page,sys_user_login_name} = Request.query;
        UserOnlineService.UserOnlineListService(limit,page,sys_user_login_name,(err,data)=>{
            if(err){
                response.send(ResultJson.GUBError());
                return;
            }
            response.send(new LayuiGrid(data.pager.totalRecord,data.pager.dataList));
            return;
        });

    }catch (e){
        response.send(ResultJson.SystemError());
        return;
    }
});

/**
 * 用户强退
 */
UserOnlineController.post("/v1/api/monitor/useronline/quit",function (Request,response){

    try{
        let {sys_user_sessionid} = Request.body;

        if(sys_user_sessionid == Request.sessionID){
            response.send(ResultJson.QuitError());
            return;
        }
        UserOnlineService.UserQuitService(sys_user_sessionid,(err,data)=>{
            if(err){
                response.send(ResultJson.GUBError());
                return;
            }
            response.send(ResultJson.MegOk("强退成功"));
            return;
        });

    }catch (e){
        response.send(ResultJson.SystemError());
        return;
    }
});


module.exports = UserOnlineController;